﻿using System;

namespace TemplatesPlugin {
    /// <summary>
    /// Templates Plugin For Notepad X
    /// Requires Notepad X 2.3 Version or higher!
    /// </summary>
    public class Plugin : Notepad_X.Plugin.IPlugin {
        private Notepad_X.Components.MenuItemX menuItem;

        private static Plugin _instance= null;
        //public static readonly string templateFolder = "Plugins/Templates/";

        /// <summary>
        /// Path for the template file
        /// </summary>
        public static string templateFile;
        /// <summary>
        /// Path for templates directory
        /// </summary>
        public static string templateDirectory;

        public static Plugin Instance {
            get {
                return _instance;
            }
        }

        public Plugin() {
            templateDirectory = System.IO.Path.Combine(Notepad_X.Main.System_ROOT, "Templates");
            templateFile = System.IO.Path.Combine(Notepad_X.Main.System_ROOT, "Templates/Templates.xml");
        }
        public string Author {
            get { return "NohponeX"; }
        }

        public string Description {
            get { return "Templates"; }
        }
        public string Name {
            get { return "Templates"; }
        }
        public string Version {
            get { return "0.5"; }
        }

        public void Initialize() {
            _instance = this;
            menuItem = new Notepad_X.Components.MenuItemX();
            menuItem.Icon = Notepad_X.Classes.Icons.@new;
            menuItem.Text = "Template";
            menuItem.Click += new EventHandler(menuItem_Click);
            Notepad_X.Static.MainInstance.system_menuItem_Get("Menu_File_New").DropDownItems.Add(menuItem);

            //To do user rights check
            String TemplatesFolder = System.IO.Path.Combine(Notepad_X.Main.System_ROOT,"Templates");
            if(!System.IO.Directory.Exists(TemplatesFolder))
                System.IO.Directory.CreateDirectory(TemplatesFolder);
        }

        void menuItem_Click(object sender, EventArgs e) {
             new TemplateBrowse().ShowDialog(Notepad_X.Static.MainInstance);
        }
        public void Dispose() {
            Notepad_X.Static.MainInstance.system_menuItem_Get("Menu_File_New").DropDownItems.Remove(menuItem);
            _instance = null;
        }

        public bool HasSettings {
            get { return true; }
        }

        public void Settings() {
            new TemplateBrowse().ShowDialog(Notepad_X.Static.MainInstance);
        }

    }
}
